#include <reg52.h>
#include <intrins.h>
#define BIAS     0X52 
#define RC256K   0X30  
#define WDTDIS1  0X0A         
#define TIMERDIS 0X08        
#define SYSEN    0X02  
#define SYSDIS   0X00     
#define LCDON    0X06    
#define LCDOFF   0X04        
#define TONEON   0X12      
#define TONEOFF  0X10      
#define uchar unsigned char
#define uint unsigned int
sbit  WRC=P2^6;
sbit CS=P2^7;
sbit DATA=P2^5;

/***************************?????******************************/
void delay(uchar i)                   //j=12???4.3us
{

  while(i--)
  {
   uchar j=0;
   while(j<8)
   j++; 
  } 
}
void SendBit_1621(uchar dat ,uchar cnt)
{
uchar i;
for(i =0; i <cnt; i ++)
	{
		if((dat&0x80)==0) 
		DATA=0;
		else DATA=1;
		WRC=0;
		delay(2);  
		WRC=1;
		dat=dat<<1;
	}
}

void SendDataBit_1621(uchar dat,uchar cnt) 
{
uchar i;
	for(i =0; i <cnt; i ++)
	{
		if((dat&0x01)==0) DATA=0;
		else DATA=1;
		WRC=0;
		delay(2);
		WRC=1;
		dat=dat>>1;
	}
}
void SendCmd(uchar command)
{
	CS=0;
	_nop_();
	_nop_();
	SendBit_1621(0x80,4); 
	SendBit_1621(command,8);
	CS=1; 
}
void Write_1621(uchar addr,uchar dat)
{
	CS=0;
	_nop_();
	_nop_();
	SendBit_1621(0xa0,3);
	SendBit_1621(addr,6); 
	SendDataBit_1621(dat,4);
	CS=1;
}
void WriteAll_1621(uchar addr,uchar *p,uchar cnt)
{
	uchar i;
	CS=0;
	_nop_();
	_nop_();
	SendBit_1621(0xa0,3); 
	SendBit_1621(addr,6); 
	for(i =0; i <cnt; i ++,p++) 
	{
		SendDataBit_1621(*p,8);
	}
	CS=1;
}
/*******************************???******************************/
void main()                                    
{
uchar a[10];
a[0]=0xBE;a[1]=0x06;a[2]=0x7c;a[3]=0x5e;a[4]=0xc6;
a[5]=0xda;a[6]=0xFa;a[7]=0x0e;a[8]=0xFe;a[9]=0xde;
SendCmd(BIAS); 
SendCmd(SYSEN); 
SendCmd(LCDON); 
SendCmd(RC256K);
WriteAll_1621(0,a,10);
}
